import 'package:flutter/material.dart';
import 'package:flutter_study/provider/follow_page_model.dart';
import 'package:flutter_study/widget/follow_page_item.dart';
import 'package:flutter_study/widget/loading_container.dart';
import 'package:flutter_study/widget/provider_widget.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

class FollowPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _FollowPageState();
  }
}

class _FollowPageState extends State<FollowPage>
    with AutomaticKeepAliveClientMixin {
  @override
  Widget build(BuildContext context) {
    super.build(context);
    return ProviderWidget<FollowPageModel>(
        onModelInit: (m) {
          m.refresh();
        },
        model: FollowPageModel(),
        builder: (context, model, child) {
          return LoadingContainer(
              loading: model.loading,
              child: SmartRefresher(
                controller: model.refreshController,
                onRefresh: model.refresh,
                onLoading: model.loadMore,
                enablePullUp: true,
                child: ListView.separated(
                  itemBuilder: (context, index) {
                    return FollowPageItem(item: model.itemList[index],);
                  },
                  itemCount: model.itemList.length,
                  separatorBuilder: (context, index) {
                    return Divider(height: 0.5);
                  },
                ),
              ),
              retry: model.retry);
        });
  }

  @override
  bool get wantKeepAlive => true;
}



